package com.ac.action;

import com.ac.entity.User;
import com.opensymphony.xwork2.ActionContext;


public class LoginAction extends DefaultAction{
	
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private User user;
	
	public String execute(){
		
		
		return INPUT;
	}
	
	public String confirm(){
		
		String sql = "select * from ac_user where userName = '" +  user.getUserName() + "'";
		String password = user.getPassword();
		user = (User) this.getHibernateBaseDao().getObject(sql, User.class);
		
		if(user == null){
			this.addActionError("userName dont exist.");
			return INPUT;
		}else if(!user.getPassword().equals(password)){
			this.addActionError("password error");
			return INPUT;
		}
		
		ActionContext.getContext().getSession().put("user", user);
		
		return SUCCESS;
	}
	
	public String logout(){
		
		
		ActionContext.getContext().getSession().clear();
		
		return "login";
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}
	
}
